package org.game.module.fight;

import java.util.Date;
import java.util.Map;

import com.google.common.collect.Maps;
import org.game.db.bean.Player;
import org.game.db.proxy.bean.PlayerDataProxy;

/**
 * @author : DengYing
 * @CreateDate : 2018年8月14日 下午2:59:31
 * @Description ：Please describe this document
 */
public class FightManager {

	private FightManager() {
	}

	private static FightManager ME = new FightManager();

	public static FightManager me() {
		return ME;
	}

	// 战斗缓存
	private Map<String, AbstractFight> cache = Maps.newConcurrentMap();

	
	public void createFight(AbstractFight fight) {
		cache.put(fight.getFightId(), fight);
	}

	public void destroyFight(AbstractFight fight) {
		cache.remove(fight.getFightId());
	}
	
	public boolean contains(AbstractFight fight){
		return cache.containsKey(fight.getFightId());
	}
	
	public AbstractFight getById(String fightId){
		return cache.get(fightId);
	}

	/**
	 * 检查助战玩家是否在冷却中
	 */
	public static boolean isHelpFightColdDown(Player player, int helpPlayerId, Date now){
		PlayerDataProxy pdp = player.getPlayerDatasFkPlayerId().getPlayerDataProxy();
		long time = pdp.getDiscreteVO().getHelpFightColdDownTime(helpPlayerId);
		return time > now.getTime();
	}
}
